<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="85%" destroy-on-close @closed="$emit('closed')" align-center>
		<el-container>
			<el-header>
				<div class="left-panel">
					<!-- <el-button type="primary" @click="back">确定</el-button> -->
					<!-- <el-button type="primary" icon="el-icon-plus" v-auth="'goods.add'" @click="add">新增</el-button> -->
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.production_code" placeholder="生产单编号" clearable @keyup.enter="upsearch"></el-input>
						<el-select v-model="search.level" placeholder="请选择" clearable>
							<el-option label="正常" :value="1"/>
							<el-option label="加急" :value="2"/>
							<el-option label="延期" :value="3"/>
						</el-select>
						<el-input v-model="search.create_time" placeholder="创建时间" clearable @keyup.enter="upsearch"></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" row-key="id" :apiObj="apiObj" highlight-current-row @row-click="selectionChange" stripe remoteSort remoteFilter border height="650"
						 :params="query">
					<!-- <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column> -->
					<el-table-column type="index" label="序号" fixed align="center" width="50"></el-table-column>
					<el-table-column label="生产单号" prop="production_code" align="center" width="120"></el-table-column>
					<el-table-column label="销售编号" prop="contract.contract_code" align="center" width="120"></el-table-column>
					<el-table-column label="开单日期" prop="open_date" align="center" width="100"></el-table-column>
					<el-table-column label="交货日期" prop="over_date" align="center" width="100"></el-table-column>
					<el-table-column label="优先级" prop="level" align="center" width="100">
						<template #default="scope">
							<el-tag v-if="scope.row.level == 2">{{ scope.row.level_text }}</el-tag>
							<el-tag v-if="scope.row.level == 1" type="success">{{ scope.row.level_text }}</el-tag>
							<el-tag v-if="scope.row.level == 3" type="danger">{{ scope.row.level_text }}</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="生产数量" prop="number_all" align="center" width="80"></el-table-column>
					<el-table-column label="入库数量" prop="enter_number_all" align="center" width="80"></el-table-column>
					<el-table-column label="发货数量" prop="deliver_number_all" align="center" width="80"></el-table-column>
					<el-table-column label="制单人" prop="create_staff_name" align="center" width="100"></el-table-column>
					<el-table-column label="制单时间" prop="create_time" align="center"></el-table-column>
					<el-table-column label="入库状态" prop="entry_status" align="center" width="100">
						<template #default="scope">
							<el-tag v-if="scope.row.entry_status == 0">{{ scope.row.entry_status_text }}</el-tag>
							<el-tag v-if="scope.row.entry_status == 1" type="warning">{{ scope.row.entry_status_text }}</el-tag>
							<el-tag v-if="scope.row.entry_status == 2" type="success">{{ scope.row.entry_status_text }}</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="发货状态" prop="deliver_status" align="center" width="100">
						<template #default="scope">
							<el-tag v-if="scope.row.deliver_status == 0">{{ scope.row.deliver_status_text }}</el-tag>
							<el-tag v-if="scope.row.deliver_status == 1" type="warning">{{ scope.row.deliver_status_text }}</el-tag>
							<el-tag v-if="scope.row.deliver_status == 2" type="success">{{ scope.row.deliver_status_text }}</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="备注" prop="remark" align="center"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	props: {
		query: {type: Object, default: () => ({})},
	},
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择生产计划单',
				edit: '选择生产计划单',
				show: '选择生产计划单'
			},
			visible: false,
			isSaveing: false,
			apiObj: this.$API.production.plan.list,
			selection: [],
			search: {
				production_code: null,
				level: null,
				create_time: null,
			},
		}
	},
	mounted() {
	},
	methods: {
		// 显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		// 选择事件
		selectionChange(selection) {
			this.$emit('success', selection)
			this.visible = false;
		},
		// 选中返回
		back() {
			this.$emit('success', this.selection, this.type)
			this.visible = false;
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		refresh() {
			for (const key in this.search) {
				this.search[key] = null;
			}
			this.$refs.table.upData(this.search)
		},
	}
}
</script>

<style></style>
